package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;

import com.zyg.pojo.EchartsData;
import com.zyg.pojo.Grade;
import com.zyg.pojo.Hostel;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface HostelMapper extends BaseMapper<Hostel> {

    @Override
    @Select("select hostel_id,hostel_name,grade_id from hostel")//一定要特别注意@One注解的使用，使用了@one就不用写连接表的sql语句
    @Results(id="hostelMap", value = {
            @Result(property="hostelId",column="hostel_id"),
            @Result(property="hostelName",column="hostel_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    List<Hostel> selectList(IPage<Hostel> page, @Param(Constants.WRAPPER) Wrapper<Hostel> queryWrapper);
    @Override
    @Select("select * from hostel where hostel_id=#{hostelId}")
    @Results(id="hostelMap1", value = {
            @Result(property="hostelId",column="hostel_id"),
            @Result(property="hostelName",column="hostel_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    Hostel selectById(Serializable hostelId);
    @Select("select g.grade_name as name,count(*) as value from hostel h inner join sys_grade g on g.grade_id = h.grade_id group by h.grade_id  ")
    List<EchartsData> getGradeIndexData();
}
